<?php

namespace Service\RpcService\RpcSearchServer;
use Service\Code\Normal;
use Service\RpcService\BaseSocketClientService;
use Service\ServiceInterface\TcpSocketClientInterface;
class ClientService extends BaseSocketClientService implements TcpSocketClientInterface
{
    protected $serviceName = 'bbc_micro_server';
    protected $service_ip   = 'SERVER_RPC_SEARCH_IP';
    protected $service_port = 'SERVER_RPC_SEARCH_PORT';
    
    /**
     * 向服务端发起socket请求.
     * @param string $method
     * @param array $argments
     * @return mixed
     */
    public function send( string $method , array $argments = [] )
    {
        set_time_limit(0);
        ini_set('memory_limit', -1);
        
        $routesMap = RpcRoutesMap::$routesMap;
        if( !isset($routesMap[$method]) ) {
            return Normal::returnCode(Normal::FAIL,"rpc socket api 【{$method}】 不存在，请核对！");
        }
        
        //请求参数
        $argments   = [
            'method'        => $routesMap[$method],
            'argments'      => $argments,
            'timestamp'     => time(),
            'request_id'    => uniqid($this->serviceName),
        ];
        return $this->openSocketInstance($argments);
    }
}